package sz.szsmk.citizencard.util;

import android.content.Context;
import android.os.Build;
import android.provider.Settings;

import java.util.UUID;

import sz.szsmk.citizencard.DaggerApplication;

/**
 * Created by chensf on 17/10/5.
 */

public class RequestParamUtils {

    private static volatile String sDeviceId;

    static {
        getDeviceId();
    }

    public static String getNonce() {
        String uuid = UUID.randomUUID().toString(); //获取UUID并转化为String对象
        uuid = uuid.replace("-", "");
        return uuid;
    }

    public static String getTimestamp() {
        return System.currentTimeMillis() + "";
    }

    public static String getKey() {
        return "GetKey.getSecureKey()";
//        return GetKey.getSecureKey();
    }

    public static String getChannelId() {
        String channelId = ACache.get(DaggerApplication.getIns()).getAsString("channelId");
        if (channelId == null){
            return "000003";
        }else {
            return channelId;
        }
    }

    public static String getDeviceId() {
        if (null == sDeviceId) { //不每次计算
            synchronized (RequestParamUtils.class) {
                if (null == sDeviceId) {
                    Context context = DaggerApplication.getIns();
                    String androidID = Settings.Secure.getString(context.getContentResolver(), Settings.Secure.ANDROID_ID);
                    String id = androidID + Build.SERIAL;
                    sDeviceId = Md5Util.md5Hash(id);
                }
            }
        }
        return sDeviceId;

    }
}
